﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo
{
    public partial class StuLogin : System.Web.UI.Page
    {
        string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DataConnectionString3"].ConnectionString;

        protected void Page_Load(object sender, EventArgs e)
        {
            string uname = this.TextBox1.Text;                //得到登陆帐号
            string pwd = this.TextBox2.Text;
            //第1步 . 建立数据连接对象
            SqlConnection con = new SqlConnection();
            con.ConnectionString = connectionString;
            con.Open();                               //打开数据库连接
            //2.操作对象
            string sqlSelect = "select * from StudentList where Name='" + uname + "' and Password='" + pwd + "'";
            SqlCommand cmd = new SqlCommand(sqlSelect, con);     //创建SqlCommand对象
            //3.读取数据
            SqlDataReader dr = cmd.ExecuteReader();   //创建SqlDataReader对象

            if (dr.Read() && !dr.Equals(""))                                  //帐号和密码正确
            {

                Session["UserName"] = uname;                      //用Session记录帐号
                Session["UserPwd"] = pwd;                //用Session记录密码
                // Server.Transfer("WebForm2.aspx", true);
                Server.Transfer("UpLoad.aspx", true);//服务器端的操作  记住罗
                // Response.Redirect("Show.aspx");
                this.TextBox3.Text = "密码是正确的！";
            }
            else                                              //帐号或密码错误
            {

                this.TextBox3.Text = "登陆失败了哦！";
            }

            con.Close();
          
        }
    }
}